"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Room_1 = require("./Room");
/**
 * 游戏总控
 */
class HallMgr {
    constructor() {
        this.users = new Map(); //暂时没用到
        this.rooms = new Set(); //匹配房合集
        this.cipherRooms = new Set(); //密码房合集
        this.room_number = 0; //创建房间的个数，同时也是room的id值
    }
    /** 匹配 */
    match(user) {
        for (let room of this.rooms) {
            if (room.checkAddPlayer(user)) {
                room.addPlayer(user);
                return;
            }
        }
        let room = new Room_1.Room(++this.room_number);
        room.addPlayer(user);
        this.rooms.add(room);
    }
    /** 创建或加入房间 */
    createOrjoinRoom(user, cipher) {
        for (let room of this.cipherRooms) {
            if (room.checkCipherRoomAddPlayer(cipher)) {
                room.addPlayer(user);
                return;
            }
        }
        let room = new Room_1.Room(++this.room_number, cipher);
        room.addPlayer(user);
        this.cipherRooms.add(room);
    }
    /** 观战 */
    watchingRoom(user, cipher) {
        for (let room of this.cipherRooms) {
            if (room.cipher == cipher) {
                room.addWatcher(user);
                user.sendObj({ "isGame": false, "type": "watchingYes", "data": room.record });
                return;
            }
        }
        user.sendObj({ "isGame": false, "type": "watchingNo" });
    }
}
exports.default = new HallMgr();
